<?php
$kd = $_GET['kode'];
include("koneksi.php");
$response = array();
$url_detail_konsultasi = mysql_query("SELECT * FROM konsultasi WHERE id_konsultasi='$kd' AND status = 'SUDAH DIJAWAB' ");

if(mysql_num_rows($url_detail_konsultasi) == 1){
	
		$p = mysql_fetch_array($url_detail_konsultasi);
		
		$response["hasil2"] = 1;
		$response["id_konsultasi"] = $p["id_konsultasi"];
		
		$response= mysql_query('SELECT * FROM konsultasi, detail_konsultasi where konsultasi.id_konsultasi=detail_konsultasi.id_konsultasi AND konsultasi.id_konsultasi="'.$kd.'"');
		
		$v = '{"artikel" : [';
		while($r=mysql_fetch_array($response))
		{
			$ob = array('"','<br>','</br>');
				$v .= '{"id" : "'.$r['id_konsultasi'].'", "tanggal-kirim" : "'.str_replace($ob,' ',strip_tags($r["tgl_konsultasi"])).'", "konsultasi" : "'.str_replace($ob,' ',strip_tags($r["konsultasi"])).'", "tanggal-balas" : "'.str_replace($ob,' ',strip_tags($r["tgl_detail"])).'", "hasil" : "'.str_replace($ob,' ',strip_tags($r["hasil_konsultasi"])).'", "penulis" : "'.str_replace($ob,' ',strip_tags($r["username"])).'"}';

		}
		$v .= ']}';
		echo $v;
		echo json_encode($response);
	}
	else{
	
		$p = mysql_fetch_array($url_detail_konsultasi);
		
		$response["hasil2"] = 0;
		$response["id_konsultasi"] = $p["id_konsultasi"];
	
		$response = mysql_query('SELECT * FROM konsultasi WHERE id_konsultasi="'.$kd.'"');
		
		$v = '{"artikel" : [';
		while($r=mysql_fetch_array($response))
		{
			$ob = array('"','<br>','</br>');
				$v .= '{"id" : "'.$r['id_konsultasi'].'", "tanggal-kirim" : "'.str_replace($ob,' ',strip_tags($r["tgl_konsultasi"])).'", "konsultasi" : "'.str_replace($ob,' ',strip_tags($r["konsultasi"])).'", "penulis" : "'.str_replace($ob,' ',strip_tags($r["username"])).'"}';

		}
		$v .= ']}';
		echo $v;
		echo json_encode($response);
	}

?>